
const {Service}=require("egg")

class UserService extends Service{

    // 模糊搜索
    // async filterService(val){
    //     console.log(val);
    //     const sql=`SELECT * FROM user_list WHERE nickname LIKE %?%`
    //     return await this.app.mysql.query(sql,[val])
    // }

    // 查看
    async showService(id){
        const sql=`SELECT * FROM user_list WHERE id=?`
        return await this.app.mysql.query(sql,[id])
    }

    // 编辑
    async editService(username,nickname,id){
        const sql=`UPDATE user_list SET username = ?, nickname = ? WHERE id = ?`
        return await this.app.mysql.query(sql,[username,nickname,id])
    }

    // 删除
    async destroyService(id){
        const sql=`DELETE FROM user_list WHERE id = ?`
        return await this.app.mysql.query(sql,[id])
    }

    // 添加
    async createService(id,username,nickname,age){
        const sql=`INSERT INTO user_list (id,username,nickname,age) VALUES(?,?,?,?)`
        return await this.app.mysql.query(sql,[id,username,nickname,age])
    }

    // 查看
    async indxService(){
        const sql=`SELECT * FROM user_list`
        return await this.app.mysql.query(sql)
    }

    // 注册
    async registerService(id,username,pwd){
        const sql=`INSERT INTO login(id,username,pwd) VALUES(?,?,?)`
        return await this.app.mysql.query(sql,[id,username,pwd])
    }

    // 判断注册用户名是否重复
    async changeName(username){
        const sql=`SELECT * FROM login WHERE username=?`
        return await this.app.mysql.query(sql,[username])
    }

    // 登录
    async loginService(username,pwd){
        const sql=`SELECT * FROM login WHERE username=? and pwd=?`
        return await this.app.mysql.query(sql,[username,pwd])
    }
}

module.exports=UserService